/*
 *  $Id: BrainPierce.cs 1221 2010-11-30 16:54:52Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Air.Spells {
    public class BrainPierce: EnemyEnchantmentCard {
        public BrainPierce(): base("001_a_s_brain_pierce") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Air;
            Value = 100;
            AddManaCost(ElementType.Air, 3);
        }

        protected override void DoAction(TargetArgs<int> args) {
            base.DoAction(args);
            args.Player.AddAffect<BrainPierceSelfAffect>();
        }
        protected override EnchantmentAffect CreateEnchantment() {
            return new BrainPierceEnemyAffect();
        }

        private class BrainPierceSelfAffect: SpellAffect<BrainPierce> {
            private static readonly Languages.CardPhrase<BrainPierce> LockMessage = new Languages.CardPhrase<BrainPierce>("lock");

            public BrainPierceSelfAffect(): base(true) {
                Add(new TimeAffect(3, new Affects.LockCards(IsSpell, LockMessage.Phrase)));
            }

            private static bool IsSpell(Player player, Card card) {
                return card.CardType == CardType.Spell;
            }

            public override bool Dispellable {
                get {
                    return false;
                }
            }
        }

        private class BrainPierceEnemyAffect: EnchantmentAffect {
            public BrainPierceEnemyAffect(): base(true) {
                DefaultDescription = true;
                Add(new TimeAffect(4));
            }

            public override string Id {
                get { return AffectManager.GetCardId<BrainPierce>("enemy"); }
            }

            public override void SetAffect() {
                base.SetAffect();
                GlobalSummary.OnManaChange += DoManaChange;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                GlobalSummary.OnManaChange -= DoManaChange;
            }

            private void DoManaChange(Player player, ElementType element, int value) {
                if (value < 0) player.DamageBy(NewDamage(DamageType.Health, -value));
            }
        }
    }
}
